package junior.db.dao.base;

import org.springframework.util.StringUtils;

public class SimpleFilterValueValidator implements FilterValueValidator {
    private boolean allowEmptyString;
    
    public SimpleFilterValueValidator() {}
    
    public SimpleFilterValueValidator(boolean allowEmptyString) {
        this.allowEmptyString = allowEmptyString;
    }
    
    @Override
	public boolean checkValue(Object val) {
		if (! checkStringValue(val)) return false;
		if (! checkNumberValue(val)) return false;
		if (! checkObjectValue(val)) return false;
		return true;
	}

	protected boolean checkStringValue(Object value) {
		if (value instanceof String) {
            if (allowEmptyString) {
                return value != null;
            }
            return StringUtils.hasText((String) value);
        }
		return true;
	}
	protected boolean checkNumberValue(Object value) {
		if (value instanceof Number) {
            return value != null;
        }
		return true;
	}
	protected boolean checkObjectValue(Object value) {
		return value != null;
	}

}
